package icu.cocoon.game.util;

import io.jsonwebtoken.lang.Assert;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.sourceforge.pinyin4j.PinyinHelper;

public class PinyinUtil {

  public static Set<String> getPinyin(char c) {
    String[] s = PinyinHelper.toHanyuPinyinStringArray(c);
    Assert.isTrue(String.valueOf(c).matches("[\\u4E00-\\u9FA5]+"),c+"不是一个中文");
    if (s==null){
      return new HashSet<>();
    }
    return Stream.of(s).collect(Collectors.toSet());
  }

  public static List<Set<String>> getPinyin(String word){
    List<Set<String>>  list = new ArrayList<>();
    for (char c : word.toCharArray()) {
      list.add(getPinyin(c));
    }
    return list;
  }

}
